/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rbh.risk.converter;

import com.rbh.risk.entity.SubEvent;
import com.rbh.risk.service.SubEventService;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

/**
 *
 * @author M
 */
@ManagedBean(name = "subEventConvert")
@RequestScoped
@FacesConverter(forClass = SubEvent.class)
public class SubEventConverter implements Converter {

    @ManagedProperty("#{subEventService}")
    private SubEventService subEventService;

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        SubEvent result = null;
        try {
            result = subEventService.getById(Integer.parseInt(value));
        } catch (Exception ex) {
        }
        return result;
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        String result = "";
        try {
            SubEvent subEvent = (SubEvent) value;
            result = subEvent.getSubEventId().toString();
        } catch (Exception ex) {
        }
        return result;
    }

    public SubEventService getSubEventService() {
        return subEventService;
    }

    public void setSubEventService(SubEventService subEventService) {
        this.subEventService = subEventService;
    }
    
}